package tech.ezrealc.fall2023.service.personnel;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tech.ezrealc.fall2023.model.personnel.student.StudentDO;
import tech.ezrealc.fall2023.model.personnel.student.StudentDTO;
import tech.ezrealc.fall2023.model.personnel.student.mapper.StudentMapper;
import tech.ezrealc.fall2023.model.user.UserDO;
import tech.ezrealc.fall2023.repository.UserRepository;
import tech.ezrealc.fall2023.repository.personnel.StudentRepository;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class StudentService {

    @Resource
    private StudentRepository studentRepository;

    @Resource
    private UserRepository userRepository;

    @Resource
    private StudentMapper studentMapper;

    public List<StudentDTO> queryAll() {
        List<StudentDO> studentDOList = studentRepository.selectAll();
        List<UserDO> userDOList = userRepository.selectByRole(UserRepository.ROLE_STUDENT);
        List<StudentDTO> studentDTOList = new ArrayList<>();
        for (StudentDO studentDO : studentDOList) {
            for (UserDO userDO : userDOList) {
                if (studentDO.getSchoolId().equals(userDO.getId())) {
                    studentDTOList.add(new StudentDTO(studentDO, userDO));
                }
            }
        }
        return studentDTOList;
    }

}
